package edu.qd.learn.day08;

/**
 * 学习一下树
 *
 * @author 布衣
 */
public class LearnTree {
    //成员变量  | 成员方法  | 成员内部类
    public class TreeNode{
        TreeNode parent;
        int data;
        TreeNode[] sons;
        public TreeNode(TreeNode parent,int data){
            this.parent = parent;
            this.data = data;
        }
    }

    public static void main(String[] args) {
        LearnTree l = new LearnTree();
        TreeNode root = l.new TreeNode(null,9);
        TreeNode f1 = l.new TreeNode(root,13);
        TreeNode f2 = l.new TreeNode(root,16);
        TreeNode[] firstSons= new TreeNode[2];
        root.sons = firstSons;
        firstSons[0] = f1;
        firstSons[1] = f2;
        System.out.println(f1.data);
        System.out.println(f1.parent.data);
        System.out.println("所有子节点");
        for (int i = 0; i < root.sons.length; i++) {
            System.out.println(root.sons[i].data);
        }
    }

}
